package com.software.advertisecenter.controller;

import com.software.advertisecenter.domain.Result;
import com.software.advertisecenter.entity.AdvertiseInfo;
import com.software.advertisecenter.service.AdvertiseService;
import com.software.advertisecenter.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.UUID;

/**
 * @Author: huanhuan
 * @Date: 2023-06-09 17:27
 **/
@RestController
@RequestMapping("/advertise_info")
@RefreshScope
public class AdvertiseController {

    @Autowired
    private AdvertiseService advertiseService;

    //返回给Android端的，筛选过isUse="Y"
    @GetMapping("/list")
    public List<AdvertiseInfo> findAll() {
        List<AdvertiseInfo> advertiseInfo = advertiseService.findAdvertiseInfosByIsUseEquals();
        return advertiseInfo;
    }
    @GetMapping("/list_page")
    public Page<AdvertiseInfo> findAll(@RequestParam(name = "pageNo", required = false, defaultValue = "1") String pageNo,
                                   @RequestParam(name = "pageSize", required = false, defaultValue = "5") String pageSize
    ) {
        Page<AdvertiseInfo> page = advertiseService.findAll(Integer.valueOf(pageNo)-1, Integer.valueOf(pageSize));
        return page;
    }

    @PostMapping("/addAdvertiseInfo")
    public Result<AdvertiseInfo> addAdvertiseInfo(
            @RequestBody AdvertiseInfo advertiseInfo){

        AdvertiseInfo modelInfo1 = advertiseService.insertAdvertiseInfo(advertiseInfo);
        return ResultUtil.success(modelInfo1);
    }

    @GetMapping(value = "/deleteAdvertiseInfoByAdvertiseId/{advertiseId}")
    public Result<AdvertiseInfo> deleteAdvertiseInfoByAdvertiseId(@PathVariable String advertiseId){
        advertiseService.deleteAdvertiseInfoByAdvertiseId(advertiseId);
        return ResultUtil.success(null);
    }

    @GetMapping(value = "/stopAdvertiseInfoByAdvertiseId/{advertiseId}")
    public Result<AdvertiseInfo> stopAdvertiseInfoByAdvertiseId(@PathVariable String advertiseId){
        advertiseService.stopAdvertiseInfoByAdvertiseId(advertiseId);
        return ResultUtil.success(null);
    }

    @GetMapping(value = "/startAdvertiseInfoByAdvertiseId/{advertiseId}")
    public Result<AdvertiseInfo> startAdvertiseInfoByAdvertiseId(@PathVariable String advertiseId){
        advertiseService.startAdvertiseInfoByAdvertiseId(advertiseId);
        return ResultUtil.success(null);
    }


    @PostMapping(value = "/updateAdvertiseInfo")
    public Result<AdvertiseInfo> updateAdvertiseInfo(@RequestBody AdvertiseInfo advertiseInfo){
        advertiseService.updateAdvertiseInfo(advertiseInfo);
        return ResultUtil.success(advertiseInfo);
    }
}
